<?php
if(!isset($MAIN)){
	include_once("includes/class.ibnfm.php");
	$MAIN = new MAIN();
}
$MAIN->users->checkLogin(true);

if(isset($_REQUEST['addProgram'])){
	$i=$_REQUEST['addProgram'];
	$circle = $MAIN->circles->getCircle($_REQUEST['circle_id']);	
	?>
	<div class="cnt_program">
	<h3>KP<?php echo($i+1);?></h3>
	<div class="cnt_program" id="cnt_program_<?php echo($i);?>" style="border:2px solid #000; margin-bottom:5px;">
		<input type="hidden" name="txt_circle_id_<?php echo($i);?>" id="txt_circle_id_<?php echo($i);?>" value="<?php echo($circle['id']);?>"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td>
					<label for="">Program</label>
					<input class="" type="text" name="txt_circle_name_<?php echo($i);?>" id="txt_circle_name_<?php echo($i);?>" value="<?php echo($circle['name']);?>"/>
				</td>
				<td>
					<label for="">Ämne</label>
					<input class="" type="text" name="txt_circle_topic_<?php echo($i);?>" id="txt_circle_topic_<?php echo($i);?>" value="<?php echo($circle['name']);?>"/>					
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td>
					<label for="">Datum</label>
					<input class=" datepicker" type="text" name="txt_circle_start_date_<?php echo($i);?>" id="txt_circle_start_date_<?php echo($i);?>" value="<?php echo($circle['start_date']);?>"/>
				</td>
				<td>
					<label for="">Starttid</label>
					<input class=" timepicker" type="text" name="txt_circle_start_<?php echo($i);?>" id="txt_circle_start_<?php echo($i);?>" value="<?php echo($circle['start']);?>"/>
				</td>
				<td>
					<label for="">Sluttid</label>
					<input class=" timepicker" type="text" name="txt_circle_end_<?php echo($i);?>" id="txt_circle_end_<?php echo($i);?>" value="<?php echo($circle['end']);?>"/>
				</td>
				<td>
					<label for="">Antal Medverkande</label>
					<input class="" type="text" name="txt_circle_number_of_participants_<?php echo($i);?>" id="txt_circle_number_of_participants_<?php echo($i);?>" value="<?php echo($circle['start']);?>"/>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td>
					<label for="">Lokal(ange namn och fullständig adress)</label>
					<input class="" type="text" name="txt_circle_place_<?php echo($i);?>" id="txt_circle_place_<?php echo($i);?>" value="<?php echo($circle['place']);?>"/>
				</td>
			</tr>
		</table>
	</div>
	</div>
	<?php
	exit();
}


if(isset($_REQUEST['addParticipan'])){
	$i=$_REQUEST['addParticipan'];
	?>
	<div class="cnt_participant" id="cnt_deltagare_<?php echo($i);?>" style="border:2px solid #000; margin-bottom:5px;">
		<input type="hidden" name="txt_participant_id_<?php echo($i);?>" id="txt_participant_id_<?php echo($i);?>" value="0"/>
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:40%;">
					<label for="txt_participant_firstname_<?php echo($i);?>">Förnamn</label>
					<input class="required" type="text" name="txt_participant_firstname_<?php echo($i);?>" id="txt_participant_firstname_<?php echo($i);?>" value=""/>
				</td>
				<td style="width:40%;">
					<label for="txt_participant_lastname_<?php echo($i);?>">Efternamn</label>
					<input class="required" type="text" name="txt_participant_lastname_<?php echo($i);?>" id="txt_participant_lastname_<?php echo($i);?>" value=""/>
				</td>
				<td style="width:20%;">
					<label for="txt_participant_pers_<?php echo($i);?>">Personnummer(ÅÅMMDD-XXXX)</label>
					<input class="required" type="text" name="txt_participant_pers_<?php echo($i);?>" id="txt_participant_pers_<?php echo($i);?>" value=""/>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:50%;">
					<label for="">Address</label>
					<input class="required" type="text" name="txt_participant_address_<?php echo($i);?>" id="txt_participant_address_<?php echo($i);?>" value=""/>
				</td>
				<td style="width:15%;">
					<label for="">Postnummer</label>
					<input class="required" type="text" name="txt_participant_zip_<?php echo($i);?>" id="txt_participant_zip_<?php echo($i);?>" value=""/>
				</td>
				<td style="width:15%;">
					<label for="">Ort</label>
					<input class="required" type="text" name="txt_participant_city_<?php echo($i);?>" id="txt_participant_city_<?php echo($i);?>" value=""/>
				</td>			
				<td style="width:20%;">
					<label for="">Telefonnummer</label>
					<input class="required" type="text" name="txt_participant_tel_<?php echo($i);?>" id="txt_participant_tel_<?php echo($i);?>" value=""/>
				</td>
			</tr>
		</table>
	</div><br/>
	<?php
	exit();
}
if(isset($_REQUEST['txt_s_reg_id'])){	
	if($MAIN->registrations->setStudyPlan($_POST)){
	?>
	<script type="text/javascript">sendInfo(null,'Dina ändringar har sparats!');(function(){document.location.href='index.php?cat=registrations&view=all';}).delay(3000);</script>
	<?php
	}
	exit();
}
if(isset($_REQUEST['txt_registration_id'])){
	if($registrationId = $MAIN->registrations->setRegistration($_REQUEST['txt_registration_id'],$_POST)){
	?>
	<script type="text/javascript">sendInfo(null,'Dina ändringar har sparats!');(function(){document.location.href='index.php?cat=registrations&view=all';}).delay(3000);</script>
	<?php
	}
	exit();
}

switch(@$_REQUEST['type']){
	default:
	case "Studiecirkel":
	case "Annan":
	if($_REQUEST['v']=="set"){
	?>
	<h1>Föranmälan</h1>
	<?php
	$reg = $MAIN->registrations->getRegistration(@$_REQUEST['id']);
	?>
	<form name="frm_registration" id="frm_registration" action="forms.php" method="post" onsubmit="return false;">
	<input type="hidden" name="txt_registration_id" value="<?php echo($reg['id']);?>"/>
	<div style="text-align:center;">
		<input class="required" <?php if($reg['semester']=='summer'){?>checked="checked"<?php }?> type="radio" name="chk_period" value="summer"/> Vårterminen (01 jan - 30 juni)
		&nbsp;&nbsp;&nbsp;
		<input class="required" <?php if($reg['semester']=='autumn'){?>checked="checked"<?php }?> type="radio" name="chk_period" value="autumn"/> Höstterminen (01 jul - 30 dec)&nbsp;&nbsp;&nbsp;
	</div>
	<?php
	$as = $MAIN->associations->getAssociation(@$reg['association_id']);
	$d=$r="";
	
	if($MAIN->currentUser['grouplevel']>=70){
		$as=$MAIN->associations->getAssociation($MAIN->currentUser['association_id']);		
		$d="readonly=\"readonly\"";
		$r="disabled=\"disabled\"";
	}
	?>
	<div style="border:2px solid #000;">		
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:65%;">
					<label for="txt_association_name">Föreningsnamn</label>
					<input type="hidden" name="txt_association_id" id="txt_association_id" value="<?php echo($as['id']);?>"/>
					<input type="hidden" name="ddl_association_member_of" id="ddl_association_member_of" value="<?php echo(@$as['member_of']);?>"/>
					<div style="position:relative;">
					<input <?php echo($d);?> class="required" type="text" name="txt_association_name" id="txt_association_name" value="<?php echo($as['name']);?>" onkeyup="associationsSuggest(this.value);" autocomplete="off"/>
					<div id="association_list"></div>
					</div>
				</td>
				<td>
					<label for="txt_association_name">Organisationsnummer</label>
					<input <?php echo($d);?> class="required validate-org" type="text" name="txt_association_org" value="<?php echo(@$as['org']);?>"/>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:65%;">
					<label for="txt_association_address">Förenings adress</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_association_address" id="txt_association_address" value="<?php echo($as['address']);?>"/>
				</td>
				<td style="width:15%;">
					<label for="txt_association_zip">Postnummer</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_association_zip" id="txt_association_zip" value="<?php echo($as['zip']);?>"/>
				</td>
				<td style="width:20%;">
					<label for="txt_association_city">Ort</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_association_city" id="txt_association_city" value="<?php echo($as['city']);?>"/>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>		
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:65%;">
					<label for="ddl_association_member_of">Medlem i:</label>		
					<div id="association_member_of_list" style="display:inline-block; width:auto;">
						<?php
						$mmemberof = explode(',',$as['member_of']);
						$membersof=$MAIN->returnArray("select * from `".tblPrefix."memberof`");			
						foreach($membersof as $m){
						?>
						<span>
						<input <?php echo($r);?> style="margin-bottom:-3px;" <?php if(in_array($m['id'],$mmemberof)){?>checked="checked"<?php }?> type="checkbox" name="chk_<?php echo($m['id']);?>" id="chk_<?php echo($m['id']);?>" value="<?php echo($m['id']);?>"/>&nbsp;&nbsp;<label for="chk_<?php echo($m['id']);?>"><?php echo($m['name']);?></label>
						</span>
						<?php
						}
						?>	
					</div>
					<br/>
				</td>
				<td>
					<!--<?php
					if($MAIN->currentUser['grouplevel']<=30){
					?>
					<label for="ddl_association_owned_by">Studiekonsulent</label> : &nbsp;&nbsp;
					<?php
					$consults = $MAIN->users->getUsers();				
					?>
					<select id="ddl_association_owned_by" name="ddl_association_owned_by" style="margin:3px 0px;" value="0">
						<option value="0">-- ange användare --</option>
					<?php
					foreach ($consults as $user) {
						if($user['grouplevel']==50){
					?>
						<option <?php if($user['id']==$as['owned_by']){?> selected="selected"<?php }?> value="<?php echo($user['id']);?>"><?php echo($user['email']);?></option>
					<?php	
						}
					}
					?>
					<?php
					}
					?>-->
				</td>
			</tr>
		</table>
		<br/>
	</div>
	<br/>
	<?php
	$circle = $MAIN->circles->getCircle($reg['circle_id']);
	?>
	<h2>Studiecirkeln/Annan Folkbildningsverksamheten</h2>
	<div style="border:2px solid #000;">
		<label for="txt_circle_name">Studiecirkelns namn</label>
		<input type="hidden" name="txt_circle_id" id="txt_circle_id" value="<?php echo($circle['id']);?>"/>
		<input type="hidden" name="txt_circle_type" value="<?php echo($_REQUEST['type']);?>"/>
		<input type="hidden" name="ddl_circle_type" value="<?php echo($_REQUEST['type']);?>"/>
		<input type="hidden" name="txt_circle_number_of_participants" value="0"/>
		<div style="position:relative;">
		<input class="required" type="text" name="txt_circle_name" id="txt_circle_name" value="<?php echo($circle['name']);?>" onkeyup="circlesSuggest(this.value);" autocomplete="off"/>
		<div id="circle_list"></div>
		</div>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<label for="txt_circle_topic">Ämne</label>
		<input class="required" type="text" name="txt_circle_topic" id="txt_circle_topic" value="<?php echo($circle['topic']);?>"/>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<label for="txt_circle_topic">Material</label>
		<input class="required" type="text" name="txt_circle_material" id="txt_circle_material" value="<?php echo($circle['material']);?>"/>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:20%;">
					<label for="txt_circle_start_date">Startdatum</label>
					<input class="datepicker required" type="text" name="txt_circle_start_date" id="txt_circle_start_date" value="<?php if($circle['start_date']==""){echo(date('Y-m-d'));}else{echo(date('Y-m-d',strtotime($circle['start_date'])));};?>"/>
				</td>
				<td style="width:20%;">
					<label for="txt_circle_day_of_the_week">Veckodag</label>
					<input type="text" name="txt_circle_day_of_the_week" id="txt_circle_day_of_the_week" value="<?php echo($circle['day_of_the_week']);?>"/>
				</td>
				<td style="width:20%;">
					<label for="txt_circle_start">Starttid</label>
					<input class="timepicker required" type="text" name="txt_circle_start" id="txt_circle_start" value="<?php echo($circle['start']);?>"/>
				</td>
				<td style="width:20%;">
					<label for="txt_circle_end">sluttid</label>
					<input class="timepicker required" type="text" name="txt_circle_end" id="txt_circle_end" value="<?php echo($circle['end']);?>"/>
				</td>
				<td style="width:20%;">
					<label for="txt_circle_number_of_meetings">Antal träffar(per termin)</label>
					<input class="required" type="text" name="txt_circle_number_of_meetings" id="txt_circle_number_of_meetings" value="<?php echo($circle['number_of_meetings']);?>"/>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:65%;">
					<label for="txt_circle_place">Studiecirkelns adress</label>
					<input class="required" type="text" name="txt_circle_place" id="txt_circle_place" value="<?php echo($circle['place']);?>"/>
				</td>
				<td style="width:15%;">
					<label for="txt_circle_zip">Postnummer</label>
					<input class="required" type="text" name="txt_circle_zip" id="txt_circle_zip" value="<?php echo($circle['zip']);?>"/>
				</td>
				<td style="width:20%;">
					<label for="txt_circle_city">Ort</label>
					<input class="required" type="text" name="txt_circle_city" id="txt_circle_city" value="<?php echo($circle['city']);?>"/>
				</td>
			</tr>
		</table>
	</div><br/>	
	<script type="text/javascript">
		var chks = $('association_member_of_list').getElements('input');
		chks.addEvent('change', function(){
			var txt=[];			
			chks.each(function(input,i){
				if(input.checked){
					txt.push(input.value);
				}
			})
			$('ddl_association_member_of').value=txt;
		});
		window.addEvent('domready', function(){	
			var datePicker = new Picker.Date($$('.datepicker'), {
				positionOffset: {x: 5, y: 0},
				pickerClass: 'datepicker_dashboard'
			});	
			var timePicker = new Picker.Date($$('.timepicker'), {
				pickOnly: 'time',
				pickerClass: 'datepicker_dashboard'
			});
		});
		/*
		 * ,
				minDate : {date: '<?php echo(date('Y-m-d'));?>',format:'Y-m-d'},
				maxDate : {date: '<?php echo(date('Y-m-d',strtotime('+1 weeks')));?>',format:'Y-m-d'}
		 */
		$('txt_circle_start_date').addEvent('change',function(){
			var date= new Date().parse(this.value);;
			$('txt_circle_day_of_the_week').value=weekday[date.getDay()];
		});
	</script>
	<h2>Cirkelledaren</h2>
	<?php
	$leader = $MAIN->persons->getPerson($reg['leader_id']);
	$d="";
	if($MAIN->currentUser['grouplevel']==70){
		$leader = $MAIN->persons->getPerson($MAIN->currentUser['person_id']);
		$d="readonly=\"readonly\"";
		$r="disabled=\"disabled\"";
	}	
	?>
	<div style="border:2px solid #000;">
		<input type="hidden" name="txt_leader_id" id="txt_leader_id" value="<?php echo($leader['id']);?>"/>
		<input type="hidden" name="txt_user_id" id="txt_user_id" value="<?php echo($leader['user_id']);?>"/>
		<input type="hidden" name="ddl_association" id="ddl_association" value="<?php echo($leader['association_id']);?>"/>
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:40%;">
					<label for="txt_leader_firstname">Förnamn</label>
					<div style="position:relative;">
					<input <?php echo($d);?> class="required" type="text" name="txt_leader_firstname" id="txt_leader_firstname" value="<?php echo($leader['firstname']);?>" onkeyup="leaderSuggest(this.value);" autocomplete="off"/>
					<div id="leader_list"></div>
					</div>
				</td>
				<td style="width:40%;">
					<label for="txt_leader_lastname">Efternamn</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_leader_lastname" id="txt_leader_lastname" value="<?php echo($leader['lastname']);?>"/>
				</td>
				<td style="width:20%;">
					<label for="txt_leader_pers">Personnummer(ÅÅMMDD-XXXX)</label>
					<input <?php echo($d);?> class="required validate-pers" type="text" name="txt_leader_pers" id="txt_leader_pers" value="<?php echo(trim($leader['pers']));?>"/>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:65%;">
					<label for="txt_leader_address">Adress</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_leader_address" id="txt_leader_address" value="<?php echo($leader['address']);?>"/>
				</td>
				<td style="width:15%;">
					<label for="txt_leader_zip">Postnummer</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_leader_zip" id="txt_leader_zip" value="<?php echo($leader['zip']);?>"/>
				</td>
				<td style="width:20%;">
					<label for="txt_leader_city">Ort</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_leader_city" id="txt_leader_city" value="<?php echo($leader['city']);?>"/>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:80%;">
					<label for="txt_leader_email">E-post adress</label>
					<input <?php echo($d);?> class="required validate-email" type="text" name="txt_leader_email" id="txt_leader_email" value="<?php echo(@$leader['email']);?>"/>
				</td>			
				<td style="width:20%;">
					<label for="txt_leader_tel">Telefonnummer</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_leader_tel" id="txt_leader_tel" value="<?php echo($leader['tel']);?>"/>
				</td>
			</tr>
		</table>
	</div><br/>
	<h2>Deltagarföteckning</h2>
	<div id="participants_list">
	<?php
	$members=explode(",",$reg['members']);	
	$min = count($members);
	if($min<3){$min=3;}
	for($i=0;$i<$min;$i++){
		@$member = $MAIN->persons->getPerson(@$members[$i]);
	?>
	<div class="cnt_participant" id="cnt_deltagare_<?php echo($i);?>" style="border:2px solid #000; margin-bottom:5px;">
		<input type="hidden" name="txt_participant_id_<?php echo($i);?>" id="txt_participant_id_<?php echo($i);?>" value="<?php echo($member['id']);?>"/>
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:40%;">
					<div style="position:relative;">
					<label for="txt_participant_firstname_<?php echo($i);?>">Förnamn</label>
					<input onkeyup="personSuggest(this.value,<?php echo($i);?>);" class="required" type="text" name="txt_participant_firstname_<?php echo($i);?>" id="txt_participant_firstname_<?php echo($i);?>" value="<?php echo($member['firstname']);?>"/>
					<div class="persons_list" id="person_list_<?php echo($i);?>"></div>
					</div>
				</td>
				<td style="width:40%;">
					<label for="txt_participant_lastname_<?php echo($i);?>">Efternamn</label>
					<input class="required" type="text" name="txt_participant_lastname_<?php echo($i);?>" id="txt_participant_lastname_<?php echo($i);?>" value="<?php echo($member['lastname']);?>"/>
				</td>
				<td style="width:20%;">
					<label for="txt_participant_pers_<?php echo($i);?>">Personnummer(ÅÅMMDD-XXXX)</label>
					<input class="required" type="text" name="txt_participant_pers_<?php echo($i);?>" id="txt_participant_pers_<?php echo($i);?>" value="<?php echo($member['pers']);?>"/>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:50%;">
					<label for="">Address</label>
					<input class="required" type="text" name="txt_participant_address_<?php echo($i);?>" id="txt_participant_address_<?php echo($i);?>" value="<?php echo($member['address']);?>"/>
				</td>
				<td style="width:15%;">
					<label for="">Postnummer</label>
					<input class="required" type="text" name="txt_participant_zip_<?php echo($i);?>" id="txt_participant_zip_<?php echo($i);?>" value="<?php echo($member['zip']);?>"/>
				</td>
				<td style="width:15%;">
					<label for="">Ort</label>
					<input class="required" type="text" name="txt_participant_city_<?php echo($i);?>" id="txt_participant_city_<?php echo($i);?>" value="<?php echo($member['city']);?>"/>
				</td>			
				<td style="width:20%;">
					<label for="">Telefonnummer</label>
					<input class="required" type="text" name="txt_participant_tel_<?php echo($i);?>" id="txt_participant_tel_<?php echo($i);?>" value="<?php echo($member['tel']);?>"/>
				</td>
			</tr>
		</table>
	</div>
	<?php
	}
	?>
	</div>
	<script type="text/javascript">
		var addParticipant = function(i){
			var participants = $$('.cnt_participant');
			var copyParticipant;
			var req = new Request.HTML(
				{url: 'forms.php',
				onSuccess:function(responseHTML){
					copyParticipant=responseHTML[1];
					$('participants_list').appendChild(copyParticipant);
				}
				}).get({'addParticipan': participants.length});			
			
		}
	</script>
		
	</form>
	<div class="tools">
		<input style="float:left;" type="button" name="btn_add_participant" value="Lägg till deltagare" onclick="addParticipant();"/>
		<input type="submit" name="btn_submit" value="Spara" onclick="sendForm('frm_registration');"/>
	</div>
	<?php
	if($reg['id']!=0){
		$studyplan = $MAIN->registrations->getStudyPlan($reg['id']);
	?>
	<hr/>
	<form name="frm_studyplan" id="frm_studyplan" action="forms.php" method="post" onsubmit="return false;">
		<input type="hidden" name="txt_s_reg_id" value="<?php echo($reg['id']);?>"/>
		<h1 style="font-style: italic;">Studiecirkelplan</h1>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="background-color:#4AD65D; border:1px solid #666;">
					<b style="font-style:italic;">Studiecirkelns namn och beskrivning</b><br/>
					<i style="font-weight:normal;">(Vad handlar studiecirkeln om, beskriv kortfattat)</i>
				</td>
			</tr>
			<tr>
				<td style="padding:0px; border:1px solid #666;">
					<textarea style="border:0px;width:97%;" name="txt_s_namedescription" id="txt_s_namedescription"><?php echo($studyplan['namedescription']);?></textarea>
				</td>
			</tr>
		</table><br/><br/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="background-color:#4AD65D; border:1px solid #666;">
					<b style="font-style:italic;">Studiematerial</b><br/>
					<i style="font-weight:normal;">(Kan vara tidskrifter, material hämtat från internet, film eller en bok… ange titel, författare, kapitel, del, etc. och använder ni egenproducerat studiematerial så ska typen av materialet samt titeln anges.)</i>
				</td>
			</tr>
			<tr>
				<td style="padding:0px; border:1px solid #666;">
					<textarea style="border:0px;width:97%;" name="txt_s_studymaterial" id="txt_s_studymaterial"><?php echo($studyplan['studymaterial']);?></textarea>
				</td>
			</tr>
		</table><br/><br/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="background-color:#4AD65D; border:1px solid #666;" colspan="6">
					<b style="font-style:italic;">Arbetsplan</b><br/>
					<i style="font-weight:normal;">(Beskriv studiecirkelns upplägg, gruppens utvecklingsprocess, omfattning i studietimmar, vad som huvudsakligen är tänkt att studeras vid varje delmoment och hur många timmar en träff omfattar ska framgå av arbetsplanen)
Observera att verksamhet där någon annan ställer krav på deltagaren att lära vissa moment, delta i viss verksamhet eller under viss tid, är inte statsbidragsberättigad t.ex. Läxhjälp.</i>
				</td>
			</tr>
			<tr>
				<td style="padding:0px; border:1px solid #666;" colspan="6">
					<textarea style="border:0px;width:97%;" name="txt_s_jobplan" id="txt_s_jobplan"><?php echo($studyplan['jobplan']);?></textarea>
				</td>
			</tr>
			<tr>
				<td style="border:1px solid #666; width:200px;"><i>Beräknat antal veckor: </i></td>
				<td style="border:1px solid #666;"><input style="width:70px;" type="text" name="txt_s_totalweeks" id="txt_s_totalweeks" value="<?php echo($studyplan['totalweeks']);?>"/></td>
				<td style="border:1px solid #666;width:200px;"><i>Beräknat antal träffar:</i></td>
				<td style="border:1px solid #666;"><input style="width:70px;" type="text" name="txt_s_totalmeetings" id="txt_s_totalmeetings" value="<?php echo($studyplan['totalmeetings']);?>"/></td>
				<td style="border:1px solid #666;width:270px;"><i>Beräknat antal stc-timmar per träff:</i></td>
				<td style="border:1px solid #666;"><input style="width:70px;" type="text" name="txt_s_hoursmeeting" id="txt_s_hoursmeeting" value="<?php echo($studyplan['hoursmeeting']);?>"/></td>
			</tr>
		</table><br/><br/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="background-color:#4AD65D; border:1px solid #666;">
					<b style="font-style:italic;">Syfte/mål med cirkeln</b><br/>
					<i style="font-weight:normal;">(Vilket resultat hoppas ni kunna uppnå med studiecirkeln)</i>
				</td>
			</tr>
			<tr>
				<td style="padding:0px; border:1px solid #666;">
					<textarea style="border:0px;width:97%;" name="txt_s_goal" id="txt_s_goal"><?php echo($studyplan['goal']);?></textarea>
				</td>
			</tr>
		</table><br/><br/>
		<div style="font-style:italic;text-decoration: underline;">
			Studiecirkelplanen ska godkännas av Ibn Rushd i samband med föranmälan av verksamheten inför start.
		</div><br/>
		<div>
			<b>Observera</b> att om studiernas uppläggning eller innehåll förändras, studiecirkeln förskjuts i tid eller timtalet förändras jämfört med det som finns angivet i den ursprungliga studiecirkelplanen, ska denna justeras av <b>deltagarna gemensamt under studiecirkelns gång</b> innan den avslutas.
		</div>
	</form>
	<div class="tools">		
		<input type="submit" name="btn_submit_s" value="Spara" onclick="sendForm('frm_studyplan');"/>
	</div>
	<?php
	}
	?>
	
	<?php
	}else{
		
	}
?>
	
<?php
	break;
	case "Kulturprogram":
		if($_REQUEST['v']=="set"){
	?>
	<h1>Anmälan av Kulturprogram</h1>
	<?php
	$reg = $MAIN->registrations->getRegistration(@$_REQUEST['id']);
	?>
	<form name="frm_registration" id="frm_registration" action="forms.php" method="post" onsubmit="return false;">
	<input type="hidden" name="txt_registration_id" value="<?php echo($reg['id']);?>"/>
	<input type="hidden" name="txt_circle_type" value="<?php echo($_REQUEST['type']);?>"/>
	<input type="hidden" name="ddl_circle_type" value="<?php echo($_REQUEST['type']);?>"/>
	<div style="text-align:center;">
		<input <?php if($reg['semester']=='summer'){?>checked="checked"<?php }?> type="radio" name="chk_period" value="summer"/> Vårterminen (01 jan - 30 juni)
		&nbsp;&nbsp;&nbsp;
		<input <?php if($reg['semester']=='autumn'){?>checked="checked"<?php }?> type="radio" name="chk_period" value="autumn"/> Höstterminen (01 jul - 30 dec)&nbsp;&nbsp;&nbsp;
	</div>
	<?php
	$as = $MAIN->associations->getAssociation(@$reg['association_id']);
	$d=$r="";
	if($MAIN->currentUser['grouplevel']>=70){
		$as=$MAIN->associations->getAssociation($MAIN->currentUser['association_id']);
		$d="readonly=\"readonly\"";
		$r="disabled=\"disabled\"";
	}
	?>
	<div style="border:2px solid #000;">
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:65%;">
					<label for="txt_association_name">Föreningsnamn</label>
					<input type="hidden" name="txt_association_id" id="txt_association_id" value="<?php echo($as['id']);?>"/>
					<input type="hidden" name="ddl_association_member_of" id="ddl_association_member_of" value="<?php echo(@$as['member_of']);?>"/>
					<div style="position:relative;">
					<input <?php echo($d);?> class="required" type="text" name="txt_association_name" id="txt_association_name" value="<?php echo($as['name']);?>" onkeyup="associationsSuggest(this.value);" autocomplete="off"/>
					<div id="association_list"></div>
					</div>
				</td>
				<td>
					<label for="txt_association_name">Organisationsnummer</label>
					<input <?php echo($d);?> class="required validate-org" type="text" name="txt_association_org" value="<?php echo(@$as['org']);?>"/>
				</td>
			</tr>
		</table>		
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:65%;">
					<label for="txt_association_address">Förenings adress</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_association_address" id="txt_association_address" value="<?php echo($as['address']);?>"/>
				</td>
				<td style="width:15%;">
					<label for="txt_association_zip">Postnummer</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_association_zip" id="txt_association_zip" value="<?php echo($as['zip']);?>"/>
				</td>
				<td style="width:20%;">
					<label for="txt_association_city">Ort</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_association_city" id="txt_association_city" value="<?php echo($as['city']);?>"/>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:65%;">
					<label for="ddl_association_member_of">Medlem i:</label>		
					<div id="association_member_of_list" style="display:inline-block;width:auto;">
						<?php
						$mmemberof = explode(',',$as['member_of']);
						$membersof=$MAIN->returnArray("select * from `".tblPrefix."memberof`");			
						foreach($membersof as $m){
						?>
						<span>
						<input <?php echo($r);?> style="margin-bottom:-3px;" <?php if(in_array($m['id'],$mmemberof)){?>checked="checked"<?php }?> type="checkbox" name="chk_<?php echo($m['id']);?>" id="chk_<?php echo($m['id']);?>" value="<?php echo($m['id']);?>"/>&nbsp;&nbsp;<label for="chk_<?php echo($m['id']);?>"><?php echo($m['name']);?></label>
						</span>
						<?php
						}
						?>	
					</div>
				</td>
				<td>
					<?php
					if($MAIN->currentUser['grouplevel']<=30){
					?>
					<label for="ddl_association_owned_by">Studiekonsulent</label> : &nbsp;&nbsp;<br/>
					<?php
					$consults = $MAIN->users->getUsers();				
					?>
					<select id="ddl_association_owned_by" name="ddl_association_owned_by" style="margin:3px 0px;" value="0">
						<option value="0">-- ange användare --</option>
					<?php
					foreach ($consults as $user) {
						if($user['grouplevel']==50){
					?>
						<option <?php if($user['id']==$as['owned_by']){?> selected="selected"<?php }?> value="<?php echo($user['id']);?>"><?php echo($user['email']);?></option>
					<?php	
						}
					}
					?>
					<?php
					}
					?>
				</td>
			</tr>
		</table>
		
		<br/><br/>
	</div>
	<br/>	
	<h2>Kontaktperson - ansvarar för att nedanstående uppgifter är korrekta</h2>
	<?php		
	$leader = $MAIN->persons->getPerson($reg['leader_id']);
	$d="";
	if($MAIN->currentUser['grouplevel']==70){
		$leader = $MAIN->persons->getPerson($MAIN->currentUser['person_id']);
		$d="readonly=\"readonly\"";
	}
	?>
	<div style="border:2px solid #000;">
		<input type="hidden" name="txt_leader_id" id="txt_leader_id" value="<?php echo($leader['id']);?>"/>
		<input type="hidden" name="txt_user_id" id="txt_user_id" value="<?php echo($leader['user_id']);?>"/>
		<input type="hidden" name="ddl_association" id="ddl_association" value="<?php echo($leader['association_id']);?>"/>
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:40%;">
					<label for="txt_leader_firstname">Förnamn</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_leader_firstname" id="txt_leader_firstname" value="<?php echo($leader['firstname']);?>"/>
				</td>
				<td style="width:40%;">
					<label for="txt_leader_lastname">Efternamn</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_leader_lastname" id="txt_leader_lastname" value="<?php echo($leader['lastname']);?>"/>
				</td>
				<td style="width:20%;">
					<label for="txt_leader_pers">Personnummer(ÅÅMMDD-XXXX)</label>
					<input <?php echo($d);?> class="required validate-pers" type="text" name="txt_leader_pers" id="txt_leader_pers" value="<?php echo($leader['pers']);?>"/>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td style="width:65%;">
					<label for="txt_leader_address">Adress</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_leader_address" id="txt_leader_address" value="<?php echo($leader['address']);?>"/>
				</td>
				<td style="width:15%;">
					<label for="txt_leader_zip">Postnummer</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_leader_zip" id="txt_leader_zip" value="<?php echo($leader['zip']);?>"/>
				</td>
				<td style="width:20%;">
					<label for="txt_leader_city">Ort</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_leader_city" id="txt_leader_city" value="<?php echo($leader['city']);?>"/>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:80%;">
					<label for="txt_leader_email">E-post adress</label>
					<input <?php echo($d);?> class="required validate-email" type="text" name="txt_leader_email" id="txt_leader_email" value="<?php echo(@$leader['email']);?>"/>
				</td>			
				<td style="width:20%;">
					<label for="txt_leader_tel">Telefonnummer</label>
					<input <?php echo($d);?> class="required" type="text" name="txt_leader_tel" id="txt_leader_tel" value="<?php echo($leader['tel']);?>"/>
				</td>
			</tr>
		</table>
	</div><br/>
	<div id="program_list">
	<?php	
	$programs=explode(",",$reg['programs']);	
	$min = count($programs);
	if($min<3){$min=3;}
	for($i=0;$i<$min;$i++){
	$circle=$MAIN->circles->getCircle(@$programs[$i]);		
	?>
	<div class="cnt_program">
	<h3>KP<?php echo($i+1);?></h3>
	<div id="cnt_program_<?php echo($i);?>" style="border:2px solid #000; margin-bottom:5px;">
		<input type="hidden" name="txt_circle_id_<?php echo($i);?>" id="txt_circle_id_<?php echo($i);?>" value="<?php echo($circle['id']);?>"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td>
					<label for="">Program</label>
					<input class="" type="text" name="txt_circle_name_<?php echo($i);?>" id="txt_circle_name_<?php echo($i);?>" value="<?php echo($circle['name']);?>"/>
				</td>
				<td>
					<label for="">Ämne</label>
					<input class="" type="text" name="txt_circle_topic_<?php echo($i);?>" id="txt_circle_topic_<?php echo($i);?>" value="<?php echo($circle['name']);?>"/>					
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td>
					<label for="">Datum</label>
					<input class=" datepicker" type="text" name="txt_circle_start_date_<?php echo($i);?>" id="txt_circle_start_date_<?php echo($i);?>" value="<?php echo($circle['start_date']);?>"/>
				</td>
				<td>
					<label for="">Starttid</label>
					<input class=" timepicker" type="text" name="txt_circle_start_<?php echo($i);?>" id="txt_circle_start_<?php echo($i);?>" value="<?php echo($circle['start']);?>"/>
				</td>
				<td>
					<label for="">Sluttid</label>
					<input class=" timepicker" type="text" name="txt_circle_end_<?php echo($i);?>" id="txt_circle_end_<?php echo($i);?>" value="<?php echo($circle['end']);?>"/>
				</td>
				<td>
					<label for="">Antal Medverkande</label>
					<input class="" type="text" name="txt_circle_number_of_participants_<?php echo($i);?>" id="txt_circle_number_of_participants_<?php echo($i);?>" value="<?php echo($circle['start']);?>"/>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td>
					<label for="">Lokal(ange namn och fullständig adress)</label>
					<input class="" type="text" name="txt_circle_place_<?php echo($i);?>" id="txt_circle_place_<?php echo($i);?>" value="<?php echo($circle['place']);?>"/>
				</td>
			</tr>
		</table>
	</div>
	</div>
	<?php
	}
	?>
	</div>
	</form>
	<script type="text/javascript">
		var chks = $('association_member_of_list').getElements('input');
		chks.addEvent('change', function(){
			var txt=[];			
			chks.each(function(input,i){
				if(input.checked){
					txt.push(input.value);
				}
			})
			$('ddl_association_member_of').value=txt;
		});
		window.addEvent('domready', function(){	
			var datePicker = new Picker.Date($$('.datepicker'), {
				positionOffset: {x: 5, y: 0},
				pickerClass: 'datepicker_dashboard'
			});	
			var timePicker = new Picker.Date($$('.timepicker'), {
				pickOnly: 'time',		
				pickerClass: 'datepicker_dashboard'
			});
		});		
		var addProgram = function(i){
			var programs = $$('.cnt_program');
			var copyProgram;
			var req = new Request.HTML(
				{url: 'forms.php',
				onSuccess:function(responseHTML){
					copyProgram=responseHTML[1];
					$('program_list').appendChild(copyProgram);
				}
				}).get({'addProgram': programs.length,'circle_id':<?php if($circle['id']!=""){echo($circle['id']);}else{echo('0');}?>});			
			
		}			
	</script>
	<div class="tools">
		<input style="float:left;" type="button" name="btn_add_participant" value="Lägg till program" onclick="addProgram();"/>
		<input type="submit" name="btn_submit" value="Spara" onclick="sendForm('frm_registration');"/>
	</div>
	<?php
		}else{
			
		}
	break;
}
?>